package com.seu.project.seuquiz.bizmq;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

/**
 * 用于创建测试程序用到的交换机和队列 (只需要在程序执行前执行一次)
 */
public class MqInitMain {

    public static void main(String[] args) {
        String EXCHANGE_NAME = "code_exchange";
        String queueName = "code_queue";
        try {
            ConnectionFactory factory = new ConnectionFactory();
            factory.setHost("127.0.0.1");
            factory.setPort(5672);
            Connection connection = factory.newConnection();
            Channel channel = connection.createChannel();
            channel.exchangeDeclare(EXCHANGE_NAME, "direct");
            channel.queueDeclare(queueName, true, false, false, null);
            channel.queueBind(queueName, EXCHANGE_NAME, "my_routingKey");
            channel.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
